/*
 * NortnacsView.java
 */
package com.nortnacs;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

import javax.swing.ListModel;

/**
 * The application's main frame.
 */
public class NortnacsView extends FrameView {

    int CalibrationCornerSize = 32;
    int formGenGeneratedHeight = 0;
    PrinterJob printJob;
    GenerationCanvas gCanvas;
    PreviewPanel pPanel;
   

    public NortnacsView(SingleFrameApplication app) {
        super(app);
        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = NortnacsApp.getApplication().getMainFrame();
            aboutBox = new NortnacsAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        NortnacsApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        analyze = new javax.swing.JButton();
        browse = new javax.swing.JButton();
        fileListScrollPane = new javax.swing.JScrollPane();
        fileList = new javax.swing.JList();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        MenuGenerateForm = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        JFrameFormGen = new javax.swing.JFrame();
        txtCols = new javax.swing.JTextField();
        txtRows = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnGenerate = new javax.swing.JButton();
        btnUseAlpha = new javax.swing.JToggleButton();
        print = new javax.swing.JButton();
        savePNG = new javax.swing.JButton();
        generateDummyData = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.nortnacs.NortnacsApp.class).getContext().getResourceMap(NortnacsView.class);
        analyze.setText(resourceMap.getString("analyze.text")); // NOI18N
        analyze.setName("analyze"); // NOI18N
        analyze.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                analyzeActionPerformed(evt);
            }
        });

        browse.setText(resourceMap.getString("browseButton.text")); // NOI18N
        browse.setName("browseButton"); // NOI18N
        browse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseActionPerformed(evt);
            }
        });

        fileListScrollPane.setName("fileListScrollPane"); // NOI18N

        fileList.setName("fileList"); // NOI18N
        fileList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                fileListMouseClicked(evt);
            }
        });
        fileListScrollPane.setViewportView(fileList);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(analyze)
                .addGap(26, 26, 26)
                .addComponent(browse)
                .addGap(18, 261, Short.MAX_VALUE)
                .addComponent(fileListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fileListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(analyze)
                        .addComponent(browse)))
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(com.nortnacs.NortnacsApp.class).getContext().getActionMap(NortnacsView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        MenuGenerateForm.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        MenuGenerateForm.setText(resourceMap.getString("MenuGenerateForm.text")); // NOI18N
        MenuGenerateForm.setName("MenuGenerateForm"); // NOI18N
        MenuGenerateForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuGenerateFormActionPerformed(evt);
            }
        });
        fileMenu.add(MenuGenerateForm);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 600, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        JFrameFormGen.setName("JFrameFormGen"); // NOI18N

        txtCols.setText(resourceMap.getString("txtCols.text")); // NOI18N
        txtCols.setName("txtCols"); // NOI18N

        txtRows.setText(resourceMap.getString("txtRows.text")); // NOI18N
        txtRows.setName("txtRows"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        btnGenerate.setText(resourceMap.getString("btnGenerate.text")); // NOI18N
        btnGenerate.setName("btnGenerate"); // NOI18N
        btnGenerate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerateActionPerformed(evt);
            }
        });

        btnUseAlpha.setText(resourceMap.getString("btnUseAlpha.text")); // NOI18N
        btnUseAlpha.setName("btnUseAlpha"); // NOI18N
        btnUseAlpha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUseAlphaActionPerformed(evt);
            }
        });

        print.setText(resourceMap.getString("print.text")); // NOI18N
        print.setName("print"); // NOI18N
        print.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printActionPerformed(evt);
            }
        });

        savePNG.setText(resourceMap.getString("savePNG.text")); // NOI18N
        savePNG.setName("savePNG"); // NOI18N
        savePNG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                savePNGActionPerformed(evt);
            }
        });

        generateDummyData.setText(resourceMap.getString("generateDummyData.text")); // NOI18N
        generateDummyData.setName("generateDummyData"); // NOI18N
        generateDummyData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateDummyDataActionPerformed(evt);
            }
        });

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jMenu1.add(jMenuItem3);

        jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        jMenu1.add(jMenuItem4);

        jMenuItem5.setText(resourceMap.getString("jMenuItem5.text")); // NOI18N
        jMenuItem5.setName("jMenuItem5"); // NOI18N
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
        jMenu2.setName("jMenu2"); // NOI18N
        jMenuBar1.add(jMenu2);

        JFrameFormGen.setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout JFrameFormGenLayout = new javax.swing.GroupLayout(JFrameFormGen.getContentPane());
        JFrameFormGen.getContentPane().setLayout(JFrameFormGenLayout);
        JFrameFormGenLayout.setHorizontalGroup(
            JFrameFormGenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JFrameFormGenLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtCols, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRows, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(445, 445, 445))
            .addGroup(JFrameFormGenLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnUseAlpha)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnGenerate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(print)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(savePNG)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(generateDummyData)
                .addContainerGap(264, Short.MAX_VALUE))
        );
        JFrameFormGenLayout.setVerticalGroup(
            JFrameFormGenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JFrameFormGenLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JFrameFormGenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCols, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(txtRows, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JFrameFormGenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUseAlpha)
                    .addComponent(btnGenerate)
                    .addComponent(print)
                    .addComponent(savePNG)
                    .addComponent(generateDummyData))
                .addContainerGap(783, Short.MAX_VALUE))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
        System.out.println("Browse button clicked");

        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setMultiSelectionEnabled(true);
        fileChooser.setFileFilter(new ImageFilter());
        int returnVal = fileChooser.showOpenDialog(mainPanel);
        switch (returnVal) {
            case (JFileChooser.APPROVE_OPTION):
                File[] files = fileChooser.getSelectedFiles();
                fileList.setListData(files);
                break;
            case (JFileChooser.CANCEL_OPTION):
                System.out.println("File access cancelled by user.");
                break;
        }
    }//GEN-LAST:event_browseActionPerformed

    private void analyzeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_analyzeActionPerformed
        //create list of all image names from list
        //create new form object for each image in list
        ListModel data = fileList.getModel();
        int listSize = data.getSize();
        Form[] listData = new Form[listSize];
        for(int i = 0; i < listSize; i++){
            try {
                System.out.println("Creating Form from : " + data.getElementAt(i).toString());
                listData[i] = new Form(data.getElementAt(i).toString());
            } catch (IOException ex) {
                Logger.getLogger(NortnacsView.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        //create new thread
        //process each form in new thread
        ProgressPane pp = new ProgressPane();
        mainPanel.getParent().add(pp);
        ProcessingThread processingThread = new ProcessingThread(listData,pp);
        Thread process = (new Thread(processingThread));
        process.start();
        mainPanel.getParent().remove(pp);
        try {
            //after processing is completed show results panel
            process.join();
            try {
                Results_Panel rp = new Results_Panel(processingThread.getForms());
            } catch (IOException ex) {
                System.out.println("Unable to get create results panel");
            }
        } catch (InterruptedException ex) {
           System.out.println("thread joining failed");
        }
        
    }//GEN-LAST:event_analyzeActionPerformed
        
    private void fileListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fileListMouseClicked
        //fix URLs
        String picURL = fileList.getSelectedValue().toString();
        picURL = picURL.replaceAll("\\\\", "\\/");

        //bring image into program
        BufferedImage image = null;
        try {
            image = ImageIO.read(new File(picURL));
        } catch (IOException ex) {
            Logger.getLogger(NortnacsView.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //create panel and append to the mainpanel
        if(pPanel!=null){
            mainPanel.remove(pPanel);
        }
        pPanel = new PreviewPanel(mainPanel,image);
        mainPanel.add(pPanel);
        pPanel.repaint();
        mainPanel.repaint();
    }//GEN-LAST:event_fileListMouseClicked

    private void MenuGenerateFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuGenerateFormActionPerformed
        JFrameFormGen.setSize((int)(800*.85), (int)(1100*.9));
        JFrameFormGen.setLocation(300, 0);
        JFrameFormGen.setVisible(true);
        
        gCanvas = new GenerationCanvas(txtRows,txtCols,btnUseAlpha);
        gCanvas.setLocation(20, 70);
        gCanvas.setVisible(true);
        gCanvas.setBackground(Color.white);
        JFrameFormGen.getContentPane().add(gCanvas);
    }//GEN-LAST:event_MenuGenerateFormActionPerformed
/*Start Buttons on Generator Form*/
    private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed
        gCanvas.repaint();
    }//GEN-LAST:event_btnGenerateActionPerformed

    private void printActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printActionPerformed
        try {
            //get a PrintJob
            PrinterJob pjob = PrinterJob.getPrinterJob();
            //set a gCanvas as the target to print
            pjob.setPrintable(gCanvas, pjob.defaultPage());
            //get the print dialog, continue if canceled is not clicked
            if (pjob.printDialog()) {
                pjob.print();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_printActionPerformed

    private void btnUseAlphaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUseAlphaActionPerformed
        if(btnUseAlpha.isSelected()){
            btnUseAlpha.setText("Use Alpha Column Names");
        }else{
            btnUseAlpha.setText("Use Numeric Column Names");
        }
        gCanvas.repaint();
    }//GEN-LAST:event_btnUseAlphaActionPerformed

    private void savePNGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePNGActionPerformed
        gCanvas.createPNG("NewForm");
    }//GEN-LAST:event_savePNGActionPerformed

    private void generateDummyDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateDummyDataActionPerformed
        int numForms = 30;
        //Random dice = new Random();
        for(int i = 0; i < numForms; i++){
            gCanvas.setDummy(true);
            gCanvas.repaint();
            gCanvas.createPNG("DummyForms/DummyForm"+i+".png");
        }
        gCanvas.setDummy(true);
    }//GEN-LAST:event_generateDummyDataActionPerformed
/*End Buttons on Generator Form*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame JFrameFormGen;
    private javax.swing.JMenuItem MenuGenerateForm;
    private javax.swing.JButton analyze;
    private javax.swing.JButton browse;
    private javax.swing.JButton btnGenerate;
    private javax.swing.JToggleButton btnUseAlpha;
    private javax.swing.JList fileList;
    private javax.swing.JScrollPane fileListScrollPane;
    private javax.swing.JButton generateDummyData;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton print;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JButton savePNG;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField txtCols;
    private javax.swing.JTextField txtRows;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
}
